﻿@model Zatify.WebUI.Admin.Models.SystemUsersListViewModel
@{
    ViewBag.Title = "System Users";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}
@section Styles
{
    <link href="@Url.Content("~/Areas/Admin/Content/zatify/Css/pop_ups.css")" rel="stylesheet" type="text/css" />
}
@section Scripts
{
    <script src="@Url.Content("~/Areas/Admin/Scripts/pop_ups.js")" type="text/javascript"></script>
    <script type="text/javascript">

        function postSystemUsersSearchForm()
        {
            $("#page").val($("#pageNum").val());
            $("#systemUsersSearchForm").submit();
        }

        function filterSystemUsersSearchForm()
        {
            $("#page").val(1);
            $("#systemUsersSearchForm").submit();
        }

        function cleareSearch()
        {
            $("#systemUsersSearchForm input").each(function(){
                
                $(this).val("");
            });
        }

        function getCheckedUsersIds()
        {
            var selectedUsersIds = new Array();

            $("#systemUsersList input[type=checkbox]:checked").each(function(){
                
                selectedUsersIds.push($(this).val());
            });

            return selectedUsersIds;
        }

        function deleteUsers() {

            var checkedUsersIds = getCheckedUsersIds();

            if(checkedUsersIds && checkedUsersIds.length > 0)
            {
                if (confirm('Are you sure you want to delete selected users?')) {

                    var data = { usersIds: checkedUsersIds };

                    $.ajax({
                        url: "@Url.Action("DeleteUsers", "SystemUsers")",
                        type: 'POST',
                        data: data,
                        traditional: true,
                        success: function (result) {

                            if(result){

                                $("#systemUsersSearchForm").submit();
                                //window.location.reload()
                            }
                            else{

                                alert("Error occured during operation.");
                            }
                        }
                    });
                }
            }
            else
            {
                alert("Check users to delete.");
            }
         }

         function activateUsers(activate)
         {
            var checkedUsersIds = getCheckedUsersIds();

            if(checkedUsersIds && checkedUsersIds.length > 0)
            {
                if (confirm('Are you sure you want to change statuses of selected users?')) {
                    var data = { usersIds: checkedUsersIds, activate: activate };

                    $.ajax({
                        url: "@Url.Action("ChangeUsersStatus", "SystemUsers")",
                        type: 'POST',
                        data: data,
                        traditional: true,
                        success: function (result) {
                        
                            if(result){

                                $("#systemUsersSearchForm").submit();
                                //window.location.reload()
                            }
                            else{

                                alert("Error occured during operation.");
                            }
                        }
                    });
                }
            }
            else
            {
                alert("Check users to change status.");
            }
         }

    </script>
}
<div id="srch" class="search_part">
    @using (Html.BeginForm("List", "SystemUsers", FormMethod.Post, new { id = "systemUsersSearchForm" }))
    {
        @Html.Hidden("page", null)
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td width="8%">
                    <label class="apps_search_label_text">
                        User ID:</label>
                </td>
                <td width="20%">@Html.TextBox("systemUserID", null, new { @class = "apps_inputbox" })
                </td>
                <td width="5%">
                    <label class="apps_search_label_text">
                        Email:</label>
                </td>
                <td width="20%">@Html.TextBox("email", null, new { @class = "apps_inputbox" })
                </td>
                <td width="7%">
                    <label class="apps_search_label_text">
                        Phone:</label>
                </td>
                <td width="18%">@Html.TextBox("phone", null, new { @class = "apps_inputbox" })
                </td>
                <td width="8%">
                    <input id="btn_search" type="submit" onclick="filterSystemUsersSearchForm();" value="Search" class="btn apps_btn apps_gray_btn" />
                </td>
                <td width="8%">
                    <input id="btn_clear_search" onclick="cleareSearch()" type="submit" value="Clear"
                        class="btn apps_btn apps_gray_btn" />
                </td>
                <td width="6%">
                    &nbsp;
                </td>
            </tr>
        </table>
    }
</div>
<!--starts search results-->
<div class="search_result_bd">
    <h4>
        Search Results</h4>
    <div id="systemUsersList" class="zatify_table_content">
        @Html.Partial("Partials/SystemUsersListControl", Model)
    </div>
</div>
<div class="clearfix">
</div>
<!--end search results-->
<!--start pagination-->
<div class="zatify_pagination">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td width="24%">
                <table>
                    <tr>
                        @Html.PageLinks(Model.PagingInfo, x => Url.Action("List", new
                           {
                               page = x,
                               systemUserID = Model.SearchModel.SystemUserID,
                               email = Model.SearchModel.Email,
                               phone = Model.SearchModel.Phone
                           }),
                           Url.Content("~/Areas/Admin/Content/zatify/Images/page_first_btn.png"),
                           Url.Content("~/Areas/Admin/Content/zatify/Images/page_last_btn.png"),
                           Url.Content("~/Areas/Admin/Content/zatify/Images/page_back.png"),
                           Url.Content("~/Areas/Admin/Content/zatify/Images/page_next.png"))
                    </tr>
                </table>
            </td>
            <td width="6%">
                Page No:
            </td>
            <td width="30%">
                @Html.DropDownList("pageNum", (IEnumerable<SelectListItem>)ViewData["pagesCount"], new { onchange = "postSystemUsersSearchForm();", @class = "select_box" })
            </td>
            <td width="2%">
                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/excel_icon.png")" alt="" title="back" border="0" />
            </td>
            <td class="pagination_no" width="20%">
                <a href="@Url.Action("SystemUsersReport", "ExcelReports")">Export to Excel</a>
            </td>
            <td width="18%">
                <span class="page_no_info">@Model.PagingInfo.TotalItems items in @Model.PagingInfo.TotalPages
                    pages</span>
            </td>
        </tr>
    </table>
</div>
<div class="clearfix">
</div>
<!--end pagination-->
@if (Model.CurrentUserRole == Zatify.Domain.Abstract.UserRole.SystemAdmin)
{
    <!--start button-->
    <div class="zatify_panel_btn">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <input name="" type="submit" class="btn apps_btn apps_gray_btn" value="Delete Selected"
                        onclick="deleteUsers()" />
                    <input name="" type="button" class="btn apps_btn apps_gray_btn" value="Suspend Selected"
                        onclick="activateUsers(0)" />
                    <input name="" type="button" class="btn apps_btn apps_gray_btn" value="Activate Selected"
                        onclick="activateUsers(1)" />
                    <input id="btnShowAddNewUser" style="margin-left: 200px;" name="" type="button" class="btn apps_btn apps_gray_btn"
                        value="Add New" />
                </td>
            </tr>
        </table>
        <div class="clearfix">
        </div>
    </div>
    <!--end button-->
    <!-- START POP-UPs -->
    <div id="overlay" class="web_dialog_overlay">
    </div>
    @Html.Partial("Partials/NewSystemUserControl", new Zatify.WebUI.Admin.Models.AddNewSystemUserViewModel())
    @Html.Partial("Partials/ChangeSystemUserPasswordControl", new Zatify.WebUI.Admin.Models.ChangeSystemUserPasswordViewModel())
    <!-- END POP-UPs -->
}